﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CrystalCore;
using CrystalCore.Actors;
using CrystalCore.AI;
using CrystalCore.Libs;
using CrystalCore.Mapping;
using CrystalCore.Structure;
using Ivory;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Barva
{
    public sealed class PathfindingTestBasic : TestBase
    {
        public static string Key = "PTB";

        //Fields
        private Player _Player;

        //Ctor
        public PathfindingTestBasic(Game game)
            : base(game)
        {

        }

        //Methods
        public override void RenderTestScreen(SpriteBatch batch, GameTime time)
        {
            ObjectHolder.LevelMap.DrawMap();
            _Player.DrawActor(time);
        }

        public override void UpdateTestScreen(GameTime time, InputControl input)
        {
            _Player.UpdateActor(time);
        }

        public override void LoadTest()
        {
            int[,] data = new int[4, 4]
            {
                {3, 3, 3, 3},
                {3, 1, 1, 3},
                {3, 1, 3, 3},
                {3, 3, 3, 1},
            }; 
            SelectionEngine.Clear();

            ObjectHolder.LevelMap = new LevelMap(Game, data);
            ObjectHolder.LevelMap.RegisterAllCells();

            _Player = new Player(new MazePosition(0, 0));
            SelectionEngine.Register(_Player);

            ObjectHolder.GameCamera = new GameCamera(Game, new Vector3(0f, 20f, -20f), _Player);

            SelectionEngine.SelectionChanged += (s,e) =>
            {
                if (e.Selected != _Player)
                {
                    //was a Tile.
                    _Player.MoveTo(e.Selected.SelectablePosition);
                }
            };
        }
    }
}
